/***********************************************
This program creates the by-year percentile graph

Figure 2A in Paper
**************************************************/

include "./config.do" 
#delimit ;
log using "./01.01.percentile_byyear.log", replace ; 
use "$datadir/percentile_byyear.dta", clear ;

rename fte_percentile percentile ;

twoway (lowess share_onlyinstate percentile if year == 1,bwidth(0.1))
       (lowess share_onlyinstate percentile if year == 5,bwidth(0.1) lpattern(dash))
       (lowess share_onlyinstate percentile if year == 10,bwidth(0.1) lpattern(longdash_dot)),
       legend(label(1 "Year = 1") label(2 "Year = 5") label(3 "Year = 10")) ytitle("Share Employed In-State")
       xtitle("National Earnings Percentile")
       ytitle("Share In-State")
       yscale(range(0(0.1)1)) 
       ylabel(0(.1)1);

graph export "$resultsdir/share_instate_byyear.png", replace ;

/**********************************************
Creating support file
**********************************************/
keep if year_postgrad == 1 | year_postgrad == 5 | year_postgrad == 10 ;

gen instate = _freq_*share_onlyinstate ; 
gen outofstate = _freq_*(1-share_onlyinstate) ;

keep percentile year_postgrad instate outofstate _freq_ ;
rename _freq_ nobs ; 

save "$supportdir/support_share_byyear.dta", replace; 
outsheet using $supportdir/support_share_byyear.csv, comma replace; 
